#include <stdio.h>
#include <stdlib.h>

//#include "decompressor/zipFileDecompressor.h"
//#include "Compressor/Compressor.h"
//#include "utils/Utils.h"
//#include "utils/ZipBrowser.h"

#define DEFAULT_ARGS 2
#define COMPRESSION_ARGS 4
#define DECOMPRESSION_ARGS 4
#define INTEGRITY_ARGS 3
#define EXPLORE_ARGS 3

#define ARGS_ERROR {printf("SoftZip:Input arguments error\n");}

#define OPTION_ERROR {printf("SoftZip:unknown option\n");}

//using namespace zipUtils;

void compress(int argc, char **argv)
{
    if (argc == COMPRESSION_ARGS)
    {
        //Compressor* compressor=new Compressor();
        //compressor->compress(argv[2],argv[3],0);
        //delete compressor;
        printf("Compress [%s] [%s]\n", argv[2], argv[3]);
    } 
    else
    {
        ARGS_ERROR;
    }
}

void decompress(int argc, char **argv)
{
    if (argc == DECOMPRESSION_ARGS)
    {
        //ZipFileDecompressor* decompressor=new ZipFileDecompressor(argv[2],argv[3]);
        //decompressor->assembleFile();
        //delete decompressor;
        printf("Decompress [%s] [%s]\n", argv[2], argv[3]);
    } 
    else
    {
        ARGS_ERROR;
    }
}

void checkIntegrity(int argc, char **argv)
{
    if (argc == INTEGRITY_ARGS)
    {
        //if(isCorruptFile(argv[2]))
        //  printf("Corrupt File");
        printf("Check Integrity [%s]\n", argv[2]);
    } 
    else
    {
        ARGS_ERROR;
    }
}

void help()
{
    FILE *fpr;
    char *c;
    char palabra[10];
    fpr = fopen("Help.txt", "r");
    do
    {
        c = fgets(palabra, 10, fpr);
        printf("%s", c);
    } while (c != NULL);
    fclose(fpr);
}
void explore(int argc, char** argv)
{
    if (argc == EXPLORE_ARGS)
    {
        //ZipBrowser* browser=new ZipBrowser();
        //browser->navigate(argv[2]);
        printf("Explore [%s]\n", argv[2]);
    } 
    else
    {
        ARGS_ERROR;
    }
}

int main(int argc, char **argv)
{
    if (argc >= DEFAULT_ARGS)
    {
        char* option = argv[1];
        char value = option[1];
        switch (value)
        {
            case 'c':
                compress(argc, argv);
                break;
            case 'd':
                decompress(argc, argv);
                break;
            case 'i':
                checkIntegrity(argc, argv);
                break;
            case 'h':
                help();
                break;
            case 'e':
                explore(argc, argv);
                break;
            default:
                OPTION_ERROR;
                break;
        }

    }
    return 0;
}
